using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	public class SqlLogAdaptor : Adaptor
	{
    private SqlLogControl sqlLogControl;
		public SqlLogAdaptor(Server server) :  base()
		{
      sqlLogControl = new SqlLogControl();
      server.SqlExecuting += new EventHandler<SqlExecutingEventArgs>(server_SqlExecuting);
      server.SqlExecuted += new EventHandler<SqlExecutingEventArgs>(server_SqlExecuted);
      sqlLogControl.ExecuteSelected += new EventHandler<SqlExecutingEventArgs>(sqlLogControl_ExecuteSelected);
		}

    public override string Text
    {
      get
      {
        return "SQL Log";
      }
    }

    public override Control GetRenderer()
    {
      return sqlLogControl;
    }

    private void server_SqlExecuting(object sender, SqlExecutingEventArgs e)
    {
      sqlLogControl.AddSql(e.Sql);
    }

    private void server_SqlExecuted(object sender, SqlExecutingEventArgs e)
    {
      sqlLogControl.AddExecuteTime();
    }

    public override int ImageIndex
    {
      get
      {
        return 25;
      }
    }

    public override object Object
    {
      get
      {
        return null;
      }
    }

    public event EventHandler<SqlExecutingEventArgs> ExecuteSelected;

    private void sqlLogControl_ExecuteSelected(object sender, SqlExecutingEventArgs e)
    {
      if (ExecuteSelected != null)
        ExecuteSelected(sender, e);
    }
  }
}
